package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteLevelPrivilegeOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.LevelPrivilegeDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegeCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegePageRequest;
import com.cskaoyan.wordmemorize.service.LevelPrivilegeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name="等级-特权管理-特权管理")
@RestController
@RequestMapping("/admin/privilege")
public class LevelPrivilegeController {
    @Resource
    LevelPrivilegeService levelPrivilegeService;
    // 分页查询(后台等级权限管理-特权管理)
    @GetMapping("/list")
    public Result<PageDTO<LevelPrivilegeDTO>> getLevelPrivilegeList(LevelPrivilegePageRequest pageRequest){
        PageDTO<LevelPrivilegeDTO> levelPrivilegeList = levelPrivilegeService.getLevelPrivilegeList(pageRequest);
        return Result.ok(levelPrivilegeList);
    }
    // 添加等级特权(后台等级权限管理-特权管理)
    @PostMapping()
    @OperateLog(dateType = "特权管理",operateType = 1)
    public Result<String> addLevelPrivilege(@RequestBody LevelPrivilegeCommand command){
        levelPrivilegeService.addLevelPrivilege(command);
        return Result.ok();
    }
    // 更新等级特权(后台等级权限管理-特权管理)
    @PutMapping
    @OperateLog(dateType = "特权管理",operateType = 2)
    public Result<String> updateLevelPrivilege(@RequestBody LevelPrivilegeCommand command){
        levelPrivilegeService.updateLevelPrivilege(command);
        return Result.ok();
    }
    // 删除等级特权(后台等级权限管理-特权管理)
    @DeleteMapping("{id}")
    @OperateLog(dateType = "特权管理",operateType = 3)
    public Result<DeleteLevelPrivilegeOperateDTO> deleteLevelPrivilege(@PathVariable Long id){
        DeleteLevelPrivilegeOperateDTO deleteLevelPrivilegeOperateDTO = levelPrivilegeService.deleteLevelPrivilege(id);
        return Result.ok(deleteLevelPrivilegeOperateDTO);
    }
    // 批量删除等级特权(后台等级权限管理-特权管理)
    @DeleteMapping("/batch")
    @OperateLog(dateType = "特权管理",operateType = 4)
    public Result<List<DeleteLevelPrivilegeOperateDTO>> batchDeleteLevelPrivilege(@RequestBody BatchDeleteCommand command){
        List<DeleteLevelPrivilegeOperateDTO> deleteLevelPrivilegeOperateDTOS = levelPrivilegeService.batchDeleteLevelPrivilege(command);
        return Result.ok(deleteLevelPrivilegeOperateDTOS);
    }
}
